package net.kem.android.positioner;

import java.util.Locale;

import android.os.Parcel;
import android.os.Parcelable;

public class Macro implements Namable {
	private static final String TEMPLATE_OBJECT =
		"<macro>" +
			"<name>%s</name>" +
			"<id>%d</id>" +
		"</macro>";//sd

	private int id;
	private String name;

	public Macro() {}

	/**
	 * This constructor for internal tests.
	 * @param id
	 * @param name
	 */
	public Macro(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toString() {
		return new StringBuilder(64).append('[').append(id).append("]: ").append(name).toString();
	}

	public String toXML() {
		String res = String.format(Locale.ENGLISH, TEMPLATE_OBJECT, id, name);
		return res;
	}

	// Parcel part
	public Macro(Parcel in) {
		id = in.readInt();
		name = in.readString();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeString(name);
	}

	public static final Parcelable.Creator<Macro> CREATOR = new Parcelable.Creator<Macro>() {
		@Override
		public Macro createFromParcel(Parcel source) {
			return new Macro(source); // using parcelable constructor
		}

		@Override
		public Macro[] newArray(int size) {
			return new Macro[size];
		}
	};
}